package me.sauce.dntest.data;

import java.util.List;

/**
 * Created by sauce on 2017/4/28.
 * Version 1.0.0
 */
public class TimerModelHelper implements IDaoHelper<TimerModel> {

    private final TimerModelDao timerModelDao;
    private static TimerModelHelper instance;

    public static TimerModelHelper getInstance() {

        if (instance == null) {
            instance = new TimerModelHelper();
        }

        return instance;
    }

    public TimerModelHelper() {
        timerModelDao = DatabaseDaoHelper.getInstance().getTimerModelDao();
    }

    @Override
    public Long addData(TimerModel timerModel) {
        return timerModelDao.insert(timerModel);
    }

    @Override
    public void deleteData(Long id) {
        timerModelDao.deleteByKey(id);
    }

    @Override
    public TimerModel getDataById(Long id) {
        return timerModelDao.load(id);
    }

    @Override
    public List<TimerModel> getAllData() {
        return timerModelDao.loadAll();
    }

    @Override
    public boolean hasKey(Long id) {
        return timerModelDao != null && timerModelDao.load(id) != null;
    }

    @Override
    public long getTotalCount() {
        return timerModelDao.count();
    }

    @Override
    public void deleteAll() {
        timerModelDao.deleteAll();
    }
}
